//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __ELASTOS_GSENSOR_H__
#define __ELASTOS_GSENSOR_H__

#include <ddk.h>
#include "drvassistant.h"
#include <nu_api.h>
#include <zenr_api.h>

#define BUFFERSIZE 128

typedef void (*SEND_FUNC)(void);

EXTERN_C void SendEventFunc(void);

EXTERN_C void SendDataFunc(void);

enum {
    BSP_GSENSOR_DOUBLE_TAP_INTERRUPT    = 0x0020,

    //selwyn 0213 added for Kortide request
    BSP_GSENSOR_RUNNER_INTERRUPT        = 0x2000,
    //~selwyn added
    BSP_GSENSOR_SHAKE_INTERRUPT         = 0x4000,
};

enum {
    BSP_DOUBLE_TAP_ENABLE   = 1,
    BSP_SHAKE_ENABLE        = 2,
    //selwyn 0213 added for Kortide request
    BSP_RUNNER_ENABLE       = 3
};

class CGSensor: public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */  Int64 offset,
        /* [in] */  Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */  Int64 offset,
        /* [in] */ const  MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */  Handle32 constrolCode,
        /* [in] */ const  MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose();

    CGSensor(){
        m_uState = GSENSOR_NONE_INTERRUPT;
        m_uTakeBack = TRUE;
        m_eEventMode = GSENSOR_SHAKE_ENABLE;
        m_eCallBackMode = GSENSOR_EventCallBack;
        m_pSendFunc = SendEventFunc;
        m_uStart = 0;
        m_uFrequency = 1;
        m_uSensitivity = 5;
        m_pWaitStateEvent = NULL;
    }
public:
    Uint32  m_uState;
    DzEvent m_event;
    Uint32  m_uszGSensorEvent[BUFFERSIZE];
    nuGSensorData  m_GSensorData[BUFFERSIZE];
    Uint32  m_uTakeBack;
    IThread *m_pIThread;
    Uint8   m_eEventMode;
    Uint8   m_eCallBackMode;
    Uint8   m_uFrequency;
    Uint8   m_uRotatetype;
    Uint8   m_uSensitivity;
    Uint32  m_uStart;
    SEND_FUNC m_pSendFunc;
    DzEvent *m_pWaitStateEvent;

};

#endif //__ELASTOS_GSENSOR_H__
